var express = require("express");
var router = express.Router();
var sql = require('../db/index');
//jz_log id序号 name访问人真实姓名 way访问方式 path访问路径 time访问时间
//开头


//分页查询
/**
 * @swagger
 *    /log_qx/pageQuery:
 *    get:
 *        description: 分页查询日志列表
 *        tags: [日志]
 *        parameters:
 *            - in: query
 *              name: page
 *              description: 页码
 *              required: true
 *              schema:
 *                type: number
 *            - in: query    
 *              name: pageSize
 *              description: 每页显示数量
 *              required: true
 *              schema:
 *                type: number
 *        responses:
 *          '200':
 *            description: 返回栏目列表
 */
//分页查询
router.get('/pageQuery', async function (req, res) {
  // 获取前端传递的参数 
  let { page, pageSize } = req.query;
  page = +page;
  pageSize = +pageSize;
  let result, result1;
  // 每页查询条数
  let offset = (page - 1) * pageSize;
    // 分页查询 
    let mysql = `select * from jz_log limit ${pageSize} offset ${offset}`;
    result = await sql.query(mysql);
    let mysql1 = `select count(*) total from jz_log limit ${pageSize} offset ${offset}`;
    result1 = await sql.query(mysql1);
  
  result = result.filter(item => {
    return item.length > 0;
  })
  console.log(result[0], '2222');
  total = result1[0][0].total;
  res.send({
    status: 200,
    message: '查询成功',
    data: result[0],
    total,
    timestamp: new Date().getTime()
  })
})

//结尾
module.exports = router;